﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL.SQLStatements;
using System.Data;
using BAL.Entities;
using BAL.Utils;

namespace DigitalAnts.App_Code.DAL.LogicComponents
{
    public class clsCountryDAL
    {
        #region --- Get All Country
        public static DataTable queryGetCountryList()
        {
            // Select all of products by user id
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblCountry";
            query.propColumn = "*";
            query.propWhere = "CountryID > 0";

            // return result
            return query.getDatatable();
        }
        #endregion ---

        #region --- Get Country by id
        public static DataTable queryGetCountryListById(clsCountry obj)
        {
            // Select all of products by user id
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblCountry";
            query.propColumn = "*";
            query.propWhere = "CountryID = '"+obj.CountryID+"'";

            // return result
            return query.getDatatable();
        }
        #endregion ---

        #region --- Add new Country
        public static bool queryAddCountry(clsCountry obj)
        {
            // Add value to column(s)
            Dictionary<String, Object> data = new Dictionary<String, Object>();
            data.Add("Country", "N'" + obj.CoutryName + "'");
            data.Add("InsertDate", "'"+clsDateTimeSetting.UTCTime()+"'");

            //Execute insert query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeInsertInto("tblCountry", data);
        }
        #endregion

        #region --- Update Country
        public static bool queryUpdateCountry(clsCountry obj)
        {
            Dictionary<String, Object> cols = new Dictionary<String, Object>();
            cols.Add("Country", "N'" + obj.CoutryName + "'");
            cols.Add("LastUpdate", "'" + clsDateTimeSetting.UTCTime() + "'");
            // Execute update query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeUpdate("tblCountry", cols, String.Format("CountryID = {0}", obj.CountryID));

        }
        #endregion

        #region ---Check Country Exist
        public static bool CheckCountryExist(clsCountry obj)
        {
            clsQueryBuilder query = new clsQueryBuilder();
            query.propColumn = "Country";
            query.propTable = "tblCountry";
            query.propWhere = "CountryID > 0 and Country = N'" + obj.CoutryName + "'";

            return query.getBoolValue();
        }
        #endregion

    }
}